package lc.数组;

import java.util.HashSet;
import java.util.Set;

/**
 * @description:
 * @author: qian
 * @createDate: 2021/10/9
 */
public class Math349两个数组的交集 {

    public int[] intersection(int[] nums1, int[] nums2) {

        Set<Integer> set1 = new HashSet<>();
        Set<Integer> set2 = new HashSet<>();


        for (int i : nums1) {
            set1.add(i);
        }

        for (int i : nums2) {
            if (set1.contains(i)) {
                set2.add(i);

            }
        }
        int size = set1.size() > set2.size() ? set2.size() : set1.size();
        int l = 0;
        int[] arr = new int[size];
        for (Integer integer : set2) {
            arr[l++] = integer;
        }
        return arr;

    }
}
